home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
et
/
et3_0-a1.lha
/
et3
/
src
/
Date.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-05-05
|
2KB
|
117 lines
#ifdef __GNUG__
#pragma implementation
#endif
#include "Date.h"
#include "Math.h"
#include "Class.h"
#include "String.h"
//---- Date --------------------------------------------------------------------
Date::Date()
{
/* ??
if ( gSystem )
gSystem->GetDate(sec, msec);
else {
sec= 0;
msec= 0;
}
*/
sec= 0;
msec= 0;
}
Date::Date(long sec, long msec)
{
this->sec= sec;
this->msec= msec;
Normalize();
}
void Date::Normalize()
{
if ( Math::Abs(msec) >= 1000 ) {
sec= sec + msec / 1000;
msec= msec % 1000;
}
if ( msec < 0 ) {
sec= sec - 1;
msec= 1000 + msec;
}
}
//---- access/conversion ----
char *Date::AsString()
{
return form("%d.%d", sec, msec);
}
//---- operators ----
Date Date::operator+(Date &d)
{
Date r(sec + d.sec, msec + d.msec);
return r;
}
Date Date::operator-(Date &d)
{
Date r(sec - d.sec, msec - d.msec);
return r;
}
Date Date::operator*(int i)
{
Date r(sec * i, msec * i);
return r;
}
Date Date::operator*(double f)
{
Date r(int(double(sec) * f), int(double(msec) * f));
return r;
}
//---- comparison ----
int Date::Compare(Date &d)
{
if ( sec < d.sec )
return -1;
if ( sec > d.sec )
return 1;
if ( msec < d.msec )
return -1;
if ( msec > d.msec )
return 1;
return 0;
}
//---- Stream operators ----
OStream &operator<< (OStream &os, Date &d)
{
return os << d.sec SP << d.msec;
}
IStream &operator>> (IStream &is, Date &d)
{
return is >> d.sec >> d.msec;
}
//---- metadef ----
SimpleMetaImpl(Date)
{
len= len;
isptr= isptr;
sprintf(buf, "%s", ((Date *) addr)->AsString());
}